<template>
    <h2>修改页面页面</h2>
    
    <table border="1">
        <tr>
            <td>会员卡号</td>
            <td>
                <input type="text" v-model="info.Code">
            </td>
        </tr>
        <tr>
            <td>姓名</td>
            <td>
                <input type="text" v-model="info.M_Name">
            </td>
        </tr>
        <tr>
            <td>手机号</td>
            <td>
                <input type="text" v-model="info.M_Phone">
            </td>
        </tr>
        <tr>
            <td>身份证号</td>
            <td>
                <input type="text" v-model="info.M_CardId">
            </td>
        </tr>
        <tr>
            <td>消费金额</td>
            <td>
                <input type="text" v-model="info.M_Money">
            </td>
        </tr>
        <tr>
            <td>积分余额</td>
            <td>
                <input type="text" v-model="info.Imgart">
            </td>
        </tr>
        <tr>
            <td>生日</td>
            <td>
                <input type="date" v-model="info.Birthday">
            </td>
        </tr>
        <tr>
            <td>会员等级</td>
            <td>
               <select v-model="info.LevelId">
                <option :value="0">--请选择--</option>
                <option  v-for="item in MemberLevel" :value="item.LevelId">{{ item.LevelName }}</option>
               </select>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="修改" @click="SaveData">
            </td>
        </tr>
    </table>
    
    </template>
    <script setup lang="ts">
    
    import { onMounted,ref } from 'vue';
    import axios from 'axios'
    
    
    
    
    
    const info =ref({
    
        Code:"",
        M_Name:"",
        M_Phone:"",
        M_CardId:"",
        Birthday:"",
        LevelId:0,
        M_Money:"",
        Imgart:"",
        M_Id:localStorage["M_Id"]
    
    
    
    })
    
    const MemberLevel=ref([{
        LevelId:0,
        LevelName:"",
    
    }])
    //创建生命周期钩子
    onMounted(()=>{
        LoadLevel();
    })
    //等级下拉
    const LoadLevel=()=>{
    axios.get('https://localhost:7177/api/Member/ShowLevel')
    .then(res=>{
     MemberLevel.value=res.data;
    
    })
    
    }
    
    //修改
    const SaveData=()=>{
    
        if(info.value.M_Name==""){
            alert("姓名不能为空");
            return;
        }
    
        var reg=/^1[3-9]\d{9}$/g;
        if(!reg.test(info.value.M_Phone)){
            alert("手机号格式不对");
            return;
        }
       
    
    axios.post('https://localhost:7177/api/Member/UpdateMember',info.value)
    .then(res=>{
        if(res.data==-1){
            alert("身份证号已经存在");
        }
        else if(res.data>0){
            alert("修改成功");
            location.href='/ShowMember'
            
        }
        else{
            alert("修改失败");
        }
    })
    
    
    }
    
    
    </script>